package com.qianfeng.bob.baidumap;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;

import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;

public class MainActivity extends AppCompatActivity {
    private MapView mMapView;
    private BaiduMap mBaiduMap;
    private boolean mIsTraffce;
    private boolean mIsHeat;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //在使用SDK各组件之前初始化context信息，传入ApplicationContext
        //注意该方法要再setContentView方法之前实现
        SDKInitializer.initialize(getApplicationContext());
        setContentView(R.layout.activity_main);
        initView();
        setImage();
        test();
    }

    private void test() {
        Log.d("ffe","fewf");
        Log.d("fefwf","fewfwef");

        WindowManager manager = getWindowManager();
        Display defaultDisplay = manager.getDefaultDisplay();
        DisplayMetrics metrics = new DisplayMetrics();
        defaultDisplay.getMetrics(metrics);
        float density = metrics.density;
        Toast.makeText(this,"density  ==  "+density,Toast.LENGTH_SHORT).show();


    }

    private void setImage() {
        //定义Maker坐标点
        LatLng point = new LatLng(39.963175, 116.400244);
        //构建Marker图标
        BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.mipmap.home);
        //构建MarkerOption，用于在地图上添加Marker
        OverlayOptions option = new MarkerOptions()
                .position(point)
                .icon(bitmap);
        //在地图上添加Marker，并显示
        mBaiduMap.addOverlay(option);
    }

    private void initView() {
        mMapView = (MapView) findViewById(R.id.bmapView);
        mBaiduMap = mMapView.getMap();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapView.onDestroy();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mMapView.onPause();
    }

    public void onClick(View view) {
        if (view!=null&&mBaiduMap!=null){
            switch (view.getId()){
                case R.id.bt_normal:
                    mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
                    break;
                case R.id.bt_weixin:
                    mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE);
                    break;
                case R.id.bt_shishi:
                    if (!mIsTraffce){
                        mIsTraffce = true;
                    }else {
                        mIsTraffce = false;
                    }
                    mBaiduMap.setTrafficEnabled(mIsTraffce);
                    break;
                case R.id.bt_reli:
                    if (!mIsHeat){
                        mIsHeat = true;
                    }else {
                        mIsHeat = false;
                    }
                    mBaiduMap.setBaiduHeatMapEnabled(mIsHeat);
                    break;
                default:
                    break;
            }
            Toast.makeText(MainActivity.this,"view  width ==  "+view.getWidth(),Toast.LENGTH_SHORT).show();
        }
    }
}
